// 基础API配置
const API_BASE_URL = 'http://localhost:5000';

// 处理API请求错误
function handleApiError(error) {
    if (error.response) {
        // 服务器返回了错误状态码
        console.error('API Error:', error.response.data);
        return error.response.data.message || '请求失败';
    } else if (error.request) {
        // 请求已发出但没有收到响应
        console.error('No response:', error.request);
        return '服务器无响应';
    } else {
        // 请求设置出错
        console.error('Request error:', error.message);
        return '请求出错';
    }
}

// 显示Toast消息
function showToast(message, type = 'success') {
    const toastContainer = document.getElementById('toastContainer');
    if (!toastContainer) {
        console.warn('Toast container not found');
        return;
    }
    
    const toast = document.createElement('div');
    toast.className = `toast show align-items-center text-white bg-${type}`;
    toast.setAttribute('role', 'alert');
    toast.setAttribute('aria-live', 'assertive');
    toast.setAttribute('aria-atomic', 'true');
    
    toast.innerHTML = `
        <div class="d-flex">
            <div class="toast-body">
                ${message}
            </div>
            <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
    `;
    
    toastContainer.appendChild(toast);
    
    setTimeout(() => {
        toast.remove();
    }, 3000);
}